#!/bin/bash
# Script to do convergence test agains the cutoff energy

# Get the number of processors, by default, 1
if [ "$#" -ge 1 ]; then
   np=$1
else
   np=4
fi

# set the environment
. ../../0-tools/environment

# Define the output file and its header
outfile='eng_ecut.dat'
echo '# encut(eV) energy(eV/cell) time-used(seconds)' > ${outfile}

# Loop over e-cut
for ecut in `seq 200 10 400`
do
# Prepare INCAR
cat > INCAR << EOF
ISTART = 0
ICHARG = 2
PREC   = Accurate
EDIFF  =  1E-6 
ALGO   = Fast
ENCUT  =  ${ecut} # cutoff energy
ISMEAR =  -5
LWAVE  = .FALSE.
LCHARG = .FALSE. 
EOF

# Run vasp
mpirun -np ${np} ${VASP}

# Collect necessary info
eng=`grep 'free  energy' OUTCAR | awk '{print $5}'`
sec=`grep 'Total CPU time used' OUTCAR |awk '{print $6}'`
echo "$ecut $eng $sec" >> ${outfile}

rm -rf WAVECAR

done

# Cleanup
rm -rf CHG CHGCAR CONTCAR DOSCAR EIGENVAL IBZKPT OSZICAR OUTCAR PBS.batch PCDAT vasprun.xml XDATCAR REPORT
